package com.ruoyi.web.controller.hatdevice.alarm;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.device.domain.DeviceAlarmHistory;
import com.ruoyi.device.domain.req.alarm.AlarmHistoryAddReq;
import com.ruoyi.device.domain.req.alarm.AlarmHistoryEditReq;
import com.ruoyi.device.domain.req.alarm.AlarmHistoryReq;
import com.ruoyi.device.service.DeviceAlarmHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author wy
 * @Description 设备报警历史记录
 * @Date 2023/12/7 14:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/alarm")
public class DeviceAlarmHistoryController extends BaseController {

    @Autowired
    private DeviceAlarmHistoryService  deviceAlarmHistoryService;

    /**
     * 设备报警历史记录查询
     * @param req
     * @return
     */
    @PreAuthorize("@ss.hasPermi('device:view:list')")
    @GetMapping(value = "/data")
    public TableDataInfo  list(AlarmHistoryReq req){
        super.startPage();
        List<DeviceAlarmHistory> list=this.deviceAlarmHistoryService.search(req);
        return super.getDataTable(list);
    }

    /**
     * 新增
     * @param req
     * @return
     */

    @PreAuthorize("@ss.hasPermi('device:view:add')")
    @PostMapping
    public Boolean add(@Valid @RequestBody AlarmHistoryAddReq req){
        Boolean result = this.deviceAlarmHistoryService.add(req);
        return result;
    }

    /**
     * 报警处理
     * @param req
     * @return
     */
    @PreAuthorize("@ss.hasPermi('device:view:edit')")
    @PutMapping
    public Boolean update(@Valid @RequestBody AlarmHistoryEditReq req){
        Boolean result = this.deviceAlarmHistoryService.edit(req);
        return result;
    }

}
